C#中获得当前任务栏的大小 |
您所在的位置:网站首页 › python3 获取任务栏高度 › C#中获得当前任务栏的大小 |
using System.Drawing; using System.Windows.Forms;
/*********************************************************************/ /* Screen */ /*********************************************************************/
// get current taskbar size(width, height), support 4 mode: taskbar bottom/right/up/left public Size getCurTaskbarSize() { int width = 0, height = 0;
if ((Screen.PrimaryScreen.Bounds.Width == Screen.PrimaryScreen.WorkingArea.Width) && (Screen.PrimaryScreen.WorkingArea.Y == 0)) { //taskbar bottom width = Screen.PrimaryScreen.WorkingArea.Width; height = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height; } else if ((Screen.PrimaryScreen.Bounds.Height == Screen.PrimaryScreen.WorkingArea.Height) && (Screen.PrimaryScreen.WorkingArea.X == 0)) { //taskbar right width = Screen.PrimaryScreen.Bounds.Width - Screen.PrimaryScreen.WorkingArea.Width; height = Screen.PrimaryScreen.WorkingArea.Height; } else if ((Screen.PrimaryScreen.Bounds.Width == Screen.PrimaryScreen.WorkingArea.Width) && (Screen.PrimaryScreen.WorkingArea.Y > 0)) { //taskbar up width = Screen.PrimaryScreen.WorkingArea.Width; //height = Screen.PrimaryScreen.WorkingArea.Y; height = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height; } else if ((Screen.PrimaryScreen.Bounds.Height == Screen.PrimaryScreen.WorkingArea.Height) && (Screen.PrimaryScreen.WorkingArea.X > 0)) { //taskbar left width = Screen.PrimaryScreen.Bounds.Width - Screen.PrimaryScreen.WorkingArea.Width; height = Screen.PrimaryScreen.WorkingArea.Height; }
return new Size(width, height); }
// get current taskbar position(X, Y), support 4 mode: taskbar bottom/right/up/left public Point getCurTaskbarLocation() { int xPos = 0, yPos = 0;
if ((Screen.PrimaryScreen.Bounds.Width == Screen.PrimaryScreen.WorkingArea.Width) && (Screen.PrimaryScreen.WorkingArea.Y == 0)) { //taskbar bottom xPos = 0; yPos = Screen.PrimaryScreen.WorkingArea.Height; } else if ((Screen.PrimaryScreen.Bounds.Height == Screen.PrimaryScreen.WorkingArea.Height) && (Screen.PrimaryScreen.WorkingArea.X == 0)) { //taskbar right xPos = Screen.PrimaryScreen.WorkingArea.Width; yPos = 0; } else if ((Screen.PrimaryScreen.Bounds.Width == Screen.PrimaryScreen.WorkingArea.Width) && (Screen.PrimaryScreen.WorkingArea.Y > 0)) { //taskbar up xPos = 0; yPos = 0; } else if ((Screen.PrimaryScreen.Bounds.Height == Screen.PrimaryScreen.WorkingArea.Height) && (Screen.PrimaryScreen.WorkingArea.X > 0)) { //taskbar left xPos = 0; yPos = 0; }
return new Point(xPos, yPos); }
// get current right bottom corner position(X, Y), support 4 mode: taskbar bottom/right/up/left public Point getCornerLocation(Size windowSize) { int xPos = 0, yPos = 0;
if ((Screen.PrimaryScreen.Bounds.Width == Screen.PrimaryScreen.WorkingArea.Width) && (Screen.PrimaryScreen.WorkingArea.Y == 0)) { //taskbar bottom xPos = Screen.PrimaryScreen.WorkingArea.Width - windowSize.Width; yPos = Screen.PrimaryScreen.WorkingArea.Height - windowSize.Height; } else if ((Screen.PrimaryScreen.Bounds.Height == Screen.PrimaryScreen.WorkingArea.Height) && (Screen.PrimaryScreen.WorkingArea.X == 0)) { //taskbar right xPos = Screen.PrimaryScreen.WorkingArea.Width - windowSize.Width; yPos = Screen.PrimaryScreen.WorkingArea.Height - windowSize.Height; } else if ((Screen.PrimaryScreen.Bounds.Width == Screen.PrimaryScreen.WorkingArea.Width) && (Screen.PrimaryScreen.WorkingArea.Y > 0)) { //taskbar up xPos = Screen.PrimaryScreen.WorkingArea.Width - windowSize.Width; yPos = Screen.PrimaryScreen.WorkingArea.Y; } else if ((Screen.PrimaryScreen.Bounds.Height == Screen.PrimaryScreen.WorkingArea.Height) && (Screen.PrimaryScreen.WorkingArea.X > 0)) { //taskbar left xPos = Screen.PrimaryScreen.WorkingArea.X; yPos = Screen.PrimaryScreen.WorkingArea.Height - windowSize.Height; }
return new Point(xPos, yPos); } |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |